def print_file_info(file_name):
    f = 0
    try:
        f = open(file_name, "r", encoding="UTF-8")
        a = f.read()
        print(a)
    except Exception as e:
        print(f"文件不存在，正在为你创建文件,错误为{e}")
    finally:
        if f:
            f.close()


def append_to_file(file_name):
    f = open(file_name, "a", encoding="UTF-8")
    f.write("Hello World!")
    f.close()
    f = open(file_name, "r", encoding="UTF-8")

    a= f.read()
    print(a)

if __name__ == "__main__":
    print_file_info("C:/Users/Lenovo/Desktop/word.txt")
    print_file_info("C:/Users/Lenovo/Desktop/Wword.txt")

    append_to_file("C:/Users/Lenovo/Desktop/wordS.txt")